<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .el-tabs__item.is-active{
      color: #058142;
    }.el-tabs__active-bar{
      background-color: #058142;
    }.el-tabs{
      background-color: #fff;
    }.el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">成本管理</div>
      </div>
      <!--  -->
      <div class="x-trtali-box" id="calali" style="margin:1rem 0"></div>
      <!--  -->
      <div class="">

        <template>
          <el-tabs v-model="activeName" @tab-click="handleClick" stretch="true">
            <el-tab-pane label="成本数据" name="first">
              <!-- <div class="x-name">岗位员工：{{}}</div> -->
              <template>
                <el-table :data="tableData">
                  <el-table-column label="核算类别" width="" fixed>
                    <template slot-scope="scope">
                      {{scope.row.title}}
                    </template>
                  </el-table-column>
                  <el-table-column label="上月结余主料/辅料" width="">
                    <template slot-scope="scope">
                      {{scope.row.last_body}}/{{scope.row.last_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column label="当日购入/调拨主料/辅料" width="">
                    <template slot-scope="scope">
                      {{scope.row.day_body}}/{{scope.row.day_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'累计购入/调拨 \n 主料/辅料'" width="">
                    <template slot-scope="scope">
                      {{scope.row.amount_body}}/{{scope.row.amount_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'当日盘点 \n 主料/辅料'" width="">
                    <template slot-scope="scope">
                      {{scope.row.check_body}}/{{scope.row.check_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'当日成本 \n 主料/辅料'" width="">
                    <template slot-scope="scope">
                      {{scope.row.day_cost_body}}/{{scope.row.day_cost_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'月累计成本 \n 主料/辅料'" width="">
                    <template slot-scope="scope">
                      {{scope.row.month_cost_body}}/{{scope.row.month_cost_assist}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'成本 \n合计'" width="">
                    <template slot-scope="scope">
                      {{scope.row.cost_amount}}
                    </template>
                  </el-table-column>
                  <el-table-column label="单品" width="70">
                    <template slot-scope="scope">
                      <div v-if="scope.row.cateid!=0"><el-button type="text" @click="gorow(scope.row.cateid,scope.row.title)">查看</el-button></div>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-tab-pane>
            <el-tab-pane label="毛利数据" name="second">
              <template>
                <el-table :data="tableDatatwo">
                  <el-table-column label="核算类别" width="70" fixed>
                    <template slot-scope="scope">
                      {{scope.row.title}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'当日毛利 \n 销售额/毛利/毛利率'" width="120">
                    <template slot-scope="scope">
                      {{scope.row.day_sale}}/{{scope.row.day_gross}}/{{scope.row.day_rate}}
                    </template>
                  </el-table-column>
                  <el-table-column :label="'月累计毛利 \n 销售额/毛利/毛利率'" width="">
                    <template slot-scope="scope">
                      {{scope.row.month_sale}}/{{scope.row.month_gross}}/{{scope.row.month_rate}}
                    </template>
                  </el-table-column>
                  <el-table-column label="单品毛利" width="70">
                    <template slot-scope="scope">
                      <div v-if="scope.row.cateid!=0">
                        <el-button type="text" @click="gorow(scope.row.cateid,scope.row.title)">查看</el-button>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-tab-pane>
          </el-tabs>
        </template>
      </div>
      <!--  -->
      <el-dialog :title="toasttitle" :visible.sync="dialogTableVisible" width="90%">
        <el-table :data="tableDatatoast">
          <el-table-column label="品名" width="" fixed>
            <template slot-scope="scope">
              {{scope.row.title}}
            </template>
          </el-table-column>
          <el-table-column label="上月结余" width="">
            <template slot-scope="scope">
              {{scope.row.last_rmb}}
            </template>
          </el-table-column>
          <el-table-column label="当日购入/调拨" width="">
            <template slot-scope="scope">
              {{scope.row.day_rmb}}
            </template>
          </el-table-column>
          <el-table-column label="累计购入/调拨" width="">
            <template slot-scope="scope">
              {{scope.row.amount_rmb}}
            </template>
          </el-table-column>
          <el-table-column label="当日盘点" width="">
            <template slot-scope="scope">
              {{scope.row.check_rmb}}
            </template>
          </el-table-column>
          <el-table-column label="当日成本" width="">
            <template slot-scope="scope">
              {{scope.row.day_cost}}
            </template>
          </el-table-column>
          <el-table-column label="月累计成本" width="">
            <template slot-scope="scope">
              {{scope.row.month_cost}}
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
      <!--  -->
      <el-dialog :title="toasttitletwo" :visible.sync="dialogTableVisibletwo" width="90%">
        <el-table :data="tableDatatoasttwo">
          <el-table-column label="产品名称" width="" fixed>
            <template slot-scope="scope">
              {{scope.row.title}}
            </template>
          </el-table-column>
          <el-table-column label="当日毛利(销售额/毛利/毛利率" width="">
            <template slot-scope="scope">
              {{scope.row.day_sale}}/{{scope.row.day_gross}}/{{scope.row.day_rate}}
            </template>
          </el-table-column>
          <el-table-column label="月累计毛利(销售额/毛利/毛利率" width="">
            <template slot-scope="scope">
              {{scope.row.month_sale}}/{{scope.row.month_gross}}/{{scope.row.month_rate}}
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/laydate/laydate.js"></script>
	<script>
apiready = function () {

  $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          cardsmonth:'',
          activeName: 'first',
          tableData:[],
          tableDatatwo:[],
          istype:'0',
          itemKey:'',
          notkey:false,
          tableDatatoast:[],
          toasttitle:'',
          dialogTableVisible:false,
          toasttitletwo:'',
          dialogTableVisibletwo:false,
          tableDatatoasttwo:[],

        }
      },
      created:function() {
        var that=this;

      },
      mounted:function(){
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        if(month<10){
          month = '' + 0 + month;
        }
        var toMonth = '' + year + month ;
        that.cardsmonth = toMonth;
        that.chancedata = toMonth;
        laydate.render({
          elem: '#calali',
          position: 'static',
          btns:['now'],
          format:'yyyyMMdd',
          // theme:'#058142',
          change:function(value,date){
            console.log(value);
            console.log(that.istype);
            that.cardsmonth = value;
            that.chancedata = value;
            if(that.istype=='0'){
              that.getdatafirst()
            }else if(that.istype=='1'){
              that.getdatatwo()
            }

          }
        });
        that.getdatafirst()

      },
      methods: {
        //选项卡
        handleClick(tab, event) {
          let id = event.target.getAttribute('id').split('-');
          let whitetab = id.join('').substring(3,9);
          let that = this;
          if(whitetab=='first'){//入职
            that.istype = '0';
            that.getdatafirst()
          }else if(whitetab=='second'){//离职
            that.istype = '1';
            that.getdatatwo()
          }
        },
        //
        gorow:function(id,title){
          let that=this;
          if(that.istype=='0'){
            that.getdescone(id,title)
          }else if(that.istype=='1'){
            that.getdesctwo(id,title)
          }
        },
        //
        getdescone:function(id,title){
          let that=this;
          that.dialogTableVisible = true;
          that.toasttitle = title;
          api.ajax({
            url:baseurl+'api/material/costAssetsList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.chancedata,
                cateid:id,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableDatatoast = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getdesctwo:function(id,title){
          let that=this;
          that.dialogTableVisibletwo = true;
          that.toasttitletwo = title;
          api.ajax({
            url:baseurl+'api/material/grossAssetsList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.chancedata,
                cateid:id,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableDatatoasttwo = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getdatafirst:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/costList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.chancedata,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableData = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getdatatwo:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/grossList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.chancedata,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableDatatwo = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
